package com.example.capsule_netty.bean;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.elasticsearch.xcontent.XContentBuilder;
import org.elasticsearch.xcontent.json.JsonXContent;

import java.io.IOException;

/**
 * @Author: zhuzhiming
 * @Date: 2022/5/16 13:36
 */
@Data
@Slf4j
public class ChatRecordBean {

    private String field;
    private String roomName;
    private String senderId;
    private String senderName;
    private String content;
    private String sendTime;


    public static XContentBuilder buildMapping() {
        XContentBuilder builder = null;
        try {
            builder = JsonXContent.contentBuilder()
                    .startObject()
                    .startObject("properties")

                    .startObject("field")
                    .field("type", "keyword")
                    .field("index", "true")
                    .endObject()

                    .startObject("senderId")
                    .field("type", "text")
                    .field("index", "true")
                    .endObject()

                    .startObject("roomName")
                    .field("type", "keyword")
                    .field("index", "true")
                    .endObject()

                    .startObject("senderName")
                    .field("type", "text")
                    .field("index", "true")
                    .field("analyzer", "ik_max_word")
                    .endObject()

                    .startObject("content")
                    .field("type", "text")
                    .field("index", "true")
                    .field("analyzer", "ik_max_word")
                    .endObject()

                    .startObject("senderTime")
                    .field("type", "text")
                    .field("index", "true")
                    .field("analyzer", "ik_smart")
                    .endObject()

                    .endObject()
                    .endObject();


        } catch (IOException e) {
            log.error(e.getMessage(), e);
        }
        return builder;
    }


}
